home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-09-04 | 825 b | 42 lines |
-
- import java.awt.Graphics;
-
- public class Primes extends java.applet.Applet {
- int highest = 0;
-
- public Primes () {
- }
-
- public void init()
- {
- Integer i = new Integer(0);
- highest = i.parseInt(getParameter("highest"));
- }
-
- public void paint(Graphics g)
- {
- int row = 1, col=1;
-
- boolean isPrime;
-
- for (int theNum = 1;theNum<=highest;theNum++) {
- isPrime = true;
- innloop: for (int i = 2; i <= theNum/2; i++){
- if ((theNum % i) == 0) {
- isPrime = false;
- break innloop;
- }
- }
- if (isPrime) {
- g.drawString(" "+theNum,30*col++,20*row);
- if (col == 10){
- col = 1;
- row++;
- }
- }
- }
- }
- }
-
-
-